#include <iostream>
#include "stdafx.h"
#include "Room.h"

using namespace std;

//*****************************************************
// PUBLIC
//*****************************************************

class Room{

public:

Room::Room(){

}

Room::Room (const string& rName, const string& rDescription)
{
    *title = rName;
    *description = rDescription;
}

Room::Room (const string& rName, const string& rDescription, const Inventory& items)
{
    *title = rName;
    *description = rDescription;
    *inventory = items;
}
//Deconstructor
Room::~Room ()
{

}

//Title Mutators
string Room::getTitle(){
	return *title;
}
void setTitle(string value){
	*title = value;
}

//Description Mutators
string Room::getDescription(){
	return *description;
}
void Room::setDescription(string value){
	*description = value;
}

//Inventory Mutators
Inventory Room::getInventory(){
	return *inventory;
}
void Room::setInventory(Inventory inv){
	*inventory = inv;
}

//LockedExit Mutators
vector<string> Room::getLockedExits(){
	return lockedExits;
}
void Room::setLockedExits(vector<string> exits){
	lockedExits = exits;
}

//HiddenExit Mutators
vector<string> Room::getHiddenExits(){
	return hiddenExits;
}
void Room::setHiddenExits(vector<string> exits){
	hiddenExits = exits;
}

//NumHiddenExits Mutators
int getNumHiddenExits(){
	return numHiddenExits;
}
void setNumHiddenExits(int value){
	numHiddenExits = value;
}

//FoundExitText Mutators
string getFoundExitText(){
	return foundExitText;
}
void setFoundExitText(string text){
	foundExitText = text;
}

void Describe(){
	cout << description << endl;
	cout << GetItemList() << endl;
	cout << GetExitList() << endl;
	cout << GetLockedExitList() << endl;
}


void showTitle(){
	cout << title<< endl;
}
//TODO
Item GetItem(const string& itemName)
        {
			for (unsigned int i = 0; i < items.size(); ++i)
			{
				if (items.at(i).GetTitle.ToLower() == itemName)
                    return items.at(i);
			}
            return *(new Item("",""));
        }


void AddExit(string direction){
	//Essentially doing exits.indexOf(direction)
	int index = -1;
	for(int i = 0; i < exits.size; ++i){
		if(exits.at(i) == direction){
			index = i;
			break;
		}
	}

	if(index == -1){
		exits.push_back(direction);
	}
}

void RemoveExit(string direction){
	//Essentially doing exits.indexOf(direction)
	int index = -1;
	for(int i = 0; i < exits.size; ++i){
		if(exits.at(i) == direction){
			index = i;
			break;
		}
	}

	if(index == -1){
		exits.(index);
	}
}        

bool CanExit(string direction){
	for(int i = 0; i < exits.size; ++i){
		if(exits.at(i) == direction){
			return true;
		}
	}
	return false;
        
}

//TODO from this point forward
void AddLockedExit(string direction)
        {
			bool hasDirection = false;
			std::vector<string>::iterator it = lockedExits.begin;
			it.operator++;
			for (unsigned int i = 0; i < lockedExits.size();it.operator++)
			{
				if ((*it).compare(direction) == 0) 
					hasDirection = true;
			}
            if (!hasDirection)
				lockedExits.push_back(direction);
			
        }

void RemoveLockedExit(string direction)
        {
bool hasDirection = false;
			std::vector<string>::iterator it = lockedExits.begin;
			it.operator++;
			for (unsigned int i = 0; i < lockedExits.size();it.operator++)
			{
				if ((*it).compare(direction) == 0) 
					hasDirection = true;
			}
            if (hasDirection)
				lockedExits.erase(it);
        }

void AddHiddenExit(string direction)
        {
			bool hasDirection = false;
			std::vector<string>::iterator it = hiddenExits.begin;
			it.operator++;
			for (unsigned int i = 0; i < hiddenExits.size();it.operator++)
			{
				if ((*it).compare(direction) == 0) 
					hasDirection = true;
			}
            if (!hasDirection)
			{
				hiddenExits.push_back(direction);
				numHiddenExits++;
			}
        }

void RemoveHiddenExits()
        {
            while ((*this).numHiddenExits > 0)
            {
				(*this).AddLockedExit(*(hiddenExits._Mylast));
				(*this).hiddenExits.pop_back();
            }
        }



void Room::OnEnter ()
{
    // Clear the screen
    cout << string(50, '\n');

    PrintName();

    // Do any events
}

Item* Room::TakeItem(const string& itemName)
{
    if ((*inventory).Contains(itemName))
    {
        return (*inventory).TakeItem(itemName);
    }

    return NULL;
}

void GiveItem(const Item& item){

}

//string& GetInventory(){
//	return *inventory;
//}

string& GetName(){
	return *title;
}

string& GetDescription(){

}
bool CanExit(const string& direction)
{
		for (unsigned int i = 0; i < exits.size(); ++i)
		{
			if (exits.at(i).compare(direction) == 0) return true;
		}
		return false;
}

void Room::PrintName ()
{
    cout << title;
}

//*****************************************************
// PRIVATE
//*****************************************************
private:

	string* title;
	string* description;
	vector<string> exits;
	vector<string> lockedExits;
	vector<string> hiddenExits;
	int numHiddenExits;
	vector<Item> items;
	string foundExitText;
	Inventory* inventory;
};